import O1HD from "../../engines/gameEngine";
import PageBase from "../Base/PageBase";
import { IPagePramsBase, IUnlockPagePrams } from "../Interface";
import mainRoot from "../MainRoot";
import UnLockPage from "./UnLockPage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class UnLockAllPage extends PageBase {

    private unlockAllCall:()=>void=null;

    private cancel:()=> void = null;

    @property({type: cc.Label, displayName: '视频观看次数'})
    lbCount: cc.Label = null;

    async OnPageOpen(prams: IUnlockPagePrams){
        super.OnPageOpen(prams);
        this.unlockAllCall=prams.allCall;
        this.cancel = prams.cancel;
    }

    protected update(dt: number): void {
        this.showUnLockPage();
    }

    showUnLockPage() {
       this.lbCount.string="("+UnLockPage.unlockAllTime+"/3)次";
    }

    onLookAllLevel() {
        O1HD.getManagers().soundMgr.playSound("mainSound/anNiu");
        if(O1HD.getServices().userSrv.getCoins() >0){
            O1HD.getServices().userSrv.setCoins(-1,true);
            UnLockPage.unlockAllTime++;
                if(UnLockPage.unlockAllTime>=3)
                {
                    this.unlockAllCall&&this.unlockAllCall()
                    this.ClosePage();
                }
        }else{
            O1HD.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(()=>{
                UnLockPage.unlockAllTime++;
                if(UnLockPage.unlockAllTime>=3)
                {
                    this.unlockAllCall&&this.unlockAllCall()
                    this.ClosePage();
                }
            },()=>{
        
            },null,'看视频解锁所有关卡')
        }
    }

    OnCloseBtn(): void {
        this.cancel&&this.cancel();
        super.OnCloseBtn();
    }


}
